var biaoqians = [{id:1,color:'red',title:'标签一'},{id:2,color:'red',title:'标签二'},{id:3,color:'red',title:'标签三'}];
function randomEmailData(size){
	var result = new Array();
	for(var i = 0; i < size ; i++){
		var o = {};
		o.id = Mock.mock('@id');
		o.title = Mock.mock('@csentence');
		o.from = Mock.mock('@name');
		o.to = Mock.mock('@name');
		o.date = Mock.mock('@datetime');
		o.content = Mock.mock('@paragraph');
		o.xinbiao = Mock.mock('@boolean(1, 9, true)');
		o.genzao = !o.xinbiao;
		var hasBq = Mock.mock('@boolean(1, 9, true)');
		if(hasBq){
			var b = Mock.mock('@integer(0, '+(biaoqians.length-1)+')');
			o.biaoqian = [biaoqians[b]];
		}else{
			o.biaoqian = [];
		}
		
		result.push(o);
	}
	return result;
}

function showMailList(mails){
	var tbody = $(".email_table").children("tbody");
	tbody.empty();
	
	var xinbiaoNum = 0;
	var xinbiaoHtml = '';
	
	var genzaoNum = 0;
	var genzaoHtml = '';
	
	mails.forEach(element => {
		//标签
		var biaoqianHtml = '';
		element.biaoqian.forEach(b => {
			biaoqianHtml+='<span class="layui-badge">'+b.title+'</span>';
		});
		
		var sl = 48; //标题栏显示长度
		element.stitle = element.title;
		if(element.stitle.length <= sl){
			var len = sl-element.stitle.length;
			element.stitle = (element.title+'<span class="small">'+element.content.substr(0,len)+'</span>');
		}
			
		//星标
	    if(element.xinbiao){
	    	xinbiaoHtml+=('<tr xinbiao>                                                                                      '+
			'				<td><input type="checkbox"></td>                                                   '+
			'				<td><i style="color:blue;">&#xe608;</i><i>&#xe66d;</i>&lt;'+element.from+'&gt;</td>  '+
			'				<td>                                                                               '+
			'				'+element.stitle+'                                                                               '+
			'				<div class="widget">'+biaoqianHtml+'<i class="layui-icon layui-icon-rate-solid"></i></div>         '+
			'				</td>                                                                              '+
			'				<td>'+element.date+'</td>                                                           '+
			'			</tr>                                                                                   ');
			xinbiaoNum++;
	    }
	    
	    //更早
	    if(element.genzao){
	    	genzaoHtml+=('<tr genzao>                                                                                      '+
			'				<td><input type="checkbox"></td>                                                   '+
			'				<td><i style="color:blue;">&#xe608;</i><i>&#xe66d;</i>&lt;'+element.from+'&gt;</td>  '+
			'				<td>                                                                               '+
			'				'+element.stitle+'                                                                               '+
			'				<div class="widget">'+biaoqianHtml+'</div>         '+
			'				</td>                                                                              '+
			'				<td>'+element.date+'</td>                                                           '+
			'			</tr>                                                                                   ');
			genzaoNum++;
	    }
	});
	
	var xinbiaoHeadHtml = '<tr class="type">'+
						'	<th><input type="checkbox"></th>'+
						'	<th><a class="s_email" c="xinbiao" href="javascript:void(0)"><i>&#xe6cc;</i></a>&nbsp;&nbsp;星标(共'+xinbiaoNum+'封)</th>'+
						'	<th></th>'+
						'	<th></th>'+
						'</tr>';
	var genzaoHeadHtml = '<tr class="type">'+
						'	<th><input type="checkbox"></th>'+
						'	<th><a class="s_email" c="genzao" href="javascript:void(0)"><i>&#xe6cc;</i></a>&nbsp;&nbsp;更早(共'+genzaoNum+'封)</th>'+
						'	<th></th>'+
						'	<th></th>'+
						'</tr>';
	tbody.append(xinbiaoHeadHtml+xinbiaoHtml);
	tbody.append(genzaoHeadHtml+genzaoHtml);
}

$(function(){
	var shoujian = randomEmailData(15);
	showMailList(shoujian);
});